package com.peng.crm.commons.utils;

/**
 * 统一响应前端的数据格式
 */

public class Result {
    /**
     * 响应码
     * 可以程序员自己定义
     *  0---->成功
     * -1---->失败
     */
    private Integer code;
    /**
     * 响应信息
     */
    private String message;
    /**
     * 响应的数据
     */
    private Object data;

    /**
     * 成功时调用
     * 新增，修改，删除
     */
    public static Result success(){
        return new Result(0,"success",null);
    }
    /**
     * 成功时调用
     * 查询
     */
    public static Result success(Object data){
        return new Result(0,"success",data);
    }
    /**
     * 失败时调用
     */
    public static Result error(){
        return new Result(-1,"error",null);
    }
    /**
     * 失败时调用
     * 自定义失败提示信息
     */
    public static Result error(Integer code,String message){
        return new Result(code,message,null);
    }
    /**
     * 失败时调用
     */
    public static Result error(Object data){
        return new Result(-1,"error",data);
    }


    public Result() {
    }

    public Result(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
